package com.mxpio.erp.technology.controller;

import com.mxpio.erp.common.technology.entity.ProdTecRoutProcAudit;
import com.mxpio.erp.common.technology.service.ProdTecRoutProcAuditService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.jpa.query.Operator;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.util.List;

@Tag(name = "ProdTecRoutProcAuditController", description = "产品工艺路线审核行接口")
@RestController
@RequestMapping("/erp/tech/prodrout/proc/audit/")
public class ProdTecRoutProcAuditController {
    @Autowired
    private ProdTecRoutProcAuditService prodTecRoutProcAuditService;

    @GetMapping("list")
    @Operation(summary = "产品工艺路线审核行列表", description = "产品工艺路线审核行列表（无分页）", method = "GET")
    public Result<List<ProdTecRoutProcAudit>> list(@Parameter(description="查询参数") Criteria criteria) throws UnsupportedEncodingException {
        List<ProdTecRoutProcAudit> bomInfoLineList = prodTecRoutProcAuditService.list(criteria);
        return Result.OK(bomInfoLineList);
    }

    @GetMapping("page")
    @Operation(summary = "产品工艺路线审核行列表", description = "产品工艺路线审核行列表（分页）", method = "GET")
    public Result<Page<ProdTecRoutProcAudit>> page(@Parameter(description="查询参数") Criteria criteria, @Parameter(description="每页条数")Integer pageSize, @Parameter(description="页号")Integer pageNo) throws UnsupportedEncodingException {
        Pageable page = PageRequest.of(pageNo-1, pageSize);
        Page<ProdTecRoutProcAudit> bomInfoLineList = prodTecRoutProcAuditService.listPage(ProdTecRoutProcAudit.class, page, criteria);
        return Result.OK(bomInfoLineList);
    }
    @GetMapping("list/{routId}")
    @Operation(summary = "根据routId获取产品工艺路线审核行", description = "根据routId获取产品工艺路线审核行", method = "GET")
    public Result<List<ProdTecRoutProcAudit>> getByBomId(@Parameter(description="routId") @PathVariable(name = "routId", required = true) String routId) {
        Criteria c = Criteria.create().addCriterion("routId", Operator.EQ, routId);
        List<ProdTecRoutProcAudit> bomInfoLineList = prodTecRoutProcAuditService.list( c);
        return Result.OK(bomInfoLineList);
    }

}
